<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>公告 - 星辰诞愿</title>
    <style>
        /* Birthday Theme Styles */
        body {
            margin: 0;
            padding: 0;
            font-family: 'Comic Sans MS', cursive, sans-serif;
            background: linear-gradient(135deg, #fff5f5 0%, #fff0f5 100%);
            min-height: 100vh;
        }
        .nav {
            display: flex;
            align-items: center;
            padding: 15px 30px;
            background: rgba(255,255,255,0.95);
            box-shadow: 0 2px 15px rgba(210, 51, 105, 0.1);
            position: fixed;
            width: 100%;
            top: 0;
            z-index: 1000;
            border-bottom: 3px solid #ff8e9e;
        }
        .nav img {
            height: 50px;
            margin-right: 15px;
        }
        .blog-title {
            font-size: 24px;
            font-weight: bold;
            color: #d23369;
            text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
            position: absolute;
            left: 100px;
        }
        .nav-links {
            display: flex;
            position: absolute;
            left: 50%;
            transform: translateX(-50%);
        }
        .nav-span {
            margin: 0 15px;
            color: #d23369;
            text-decoration: none;
            font-weight: bold;
            padding: 5px 10px;
            border-radius: 5px;
            transition: all 0.3s;
        }
        .nav-span:hover {
            background-color: #ffebee;
            color: #ff4081;
        }
        .space {
            flex-grow: 1;
        }
        .container {
            display: flex;
            padding-top: 90px;
            min-height: calc(100vh - 90px);
            box-sizing: border-box;
        }
        .left, .center, .right {
            padding: 20px;
            box-sizing: border-box;
        }
        .left {
            width: 25%;
            background: rgba(255,255,255,0.8);
            border-left: 2px dashed #ffb8c6;
            height: calc(100vh - 130px);
            overflow-y: auto;
        }
        .center {
            width: 50%;
            background: rgba(255,255,255,0.9);
            height: calc(100vh - 130px);
            overflow-y: auto;
        }
        .right {
            width: 25%;
            background: rgba(255,255,255,0.8);
            border-left: 2px dashed #ffb8c6;
            height: calc(100vh - 130px);
            overflow-y: auto;
        }
        .card {
            background: white;
            border-radius: 15px;
            padding: 20px;
            margin-bottom: 20px;
            box-shadow: 0 5px 15px rgba(210, 51, 105, 0.1);
            border: 1px solid #ffd6de;
            position: relative;
        }
        .card:before {
            content: "🎀";
            position: absolute;
            top: -10px;
            left: -10px;
            font-size: 20px;
        }
        .user-info img {
            width: 100px;
            height: 100px;
            border-radius: 25%;
            border: 3px solid #ff8e9e;
            object-fit: cover;
            margin-bottom: 15px;
        }
        .user-info h3 {
            color: #d23369;
            margin: 10px 0;
        }
        .user-info p {
            color: #666;
            margin: 5px 0;
        }
        .developer-info {
            text-align: center;
        }
        .developer-info h3 {
            color: #d23369;
            border-bottom: 2px dotted #ffb8c6;
            padding-bottom: 10px;
        }
        .developer-info p {
            color: #666;
            line-height: 1.6;
            margin: 8px 0;
        }
        .copyright {
            font-size: 12px;
            color: #999;
            margin-top: 15px;
        }
        .notice-item {
            padding: 15px;
            margin-bottom: 20px;
            background: #fff9fa;
            border-radius: 10px;
            border-left: 5px solid #ff8e9e;
        }
        .notice-title {
            font-size: 18px;
            font-weight: bold;
            color: #d23369;
            margin-bottom: 10px;
            display: flex;
            align-items: center;
        }
        .notice-title:before {
            content: "📢";
            margin-right: 10px;
        }
        .notice-content {
            color: #555;
            line-height: 1.6;
            margin-bottom: 10px;
        }
        .notice-time {
            color: #999;
            font-size: 12px;
            text-align: right;
        }
        .notice-important {
            background: #fff0f0;
            border-left: 5px solid #ff6b88;
        }
        .notice-important .notice-title {
            color: #ff4081;
        }
    </style>
</head>
<body>
    <div class="nav">
        <img src="pic/cat.jpg" alt="小猫" title="小公主生日快乐">
        <span class="blog-title">星辰诞愿 - 公告</span>
        <div class="nav-links">
            <a class="nav-span" href="home.html">主页</a>
        </div>
        <div class="space"></div>
    </div>
    <div class="container">
        <div class="left">
            <div class="card developer-info">
                <img src="pic/mohan.jpg" title="小公主生日快乐" alt="开发者logo" width="320">
                <p class="birthday-theme">🎁 让祝福传递温暖 🎁</p>
                <p class="copyright">© 2025 星辰诞愿 版权所有</p>
                <div style="width: 320px; margin: 20px auto 0;">
                    <button style="
                background-color: #d23369;
                color: white;
                border: none;
                padding: 15px 0;
                border-radius: 25px;
                font-weight: bold;
                cursor: pointer;
                box-shadow: 0 4px 8px rgba(210, 51, 105, 0.3);
                transition: all 0.3s;
                width: 100%;
                font-size: 16px;
                display: block;
            " onmouseover="this.style.backgroundColor='#ff4081'"
                            onmouseout="this.style.backgroundColor='#d23369'" onclick="publish()">
                        🚀 发布新公告
                    </button>
                </div>
            </div>
        </div>
        <div class="center">
            <div class="card">
                <h2 style="text-align: center; color: #d23369; margin-bottom: 20px;">✨ 系统公告 ✨</h2>
                <div class="notice-item notice-important" id="notice">
                    <!--JS动态拼接-->
                </div>
            </div>
        </div>
        <div class="right">
            <div class="card developer-info">
                <img id="user-develop" src="pic/logo.png" title="小公主生日快乐" alt="开发者logo" width="320">
                <h3>星辰诞愿系统</h3>
                <p>✨ 生日祝福专属平台 ✨</p>
                <p>版本: Linhan002 生日特别版</p>
                <p>开发者: 九转苍翎</p>
                <p>联系QQ: 3210728077</p>
                <p>邮箱: 3210728077@qq.com</p>
                <p class="birthday-theme">🎁 让祝福传递温暖 🎁</p>
                <p class="copyright">© 2025 星辰诞愿 版权所有</p>
            </div>
        </div>
    </div>
    <script src="js/jquery.min.js"></script>
    <script src="js/common.js"></script>
    <script>
        let power;
        $.ajax({
            type: "get",
            url: "user/getLoginUser",
            success:function (result){
                if (result.code === "SUCCESS" && result.data != null){
                    power = result.data.power;
                }else {
                    alert(result.errorMessage);
                }
            },error:function (error){
                if (error != null && error.status === 401){
                    location.href = "login.html";
                }
            }
        })
        //发布公告
        function publish(){
            if (power === 0){
                alert("您没有发布公告的权限")
            }else {
                location.href = "notice_publish.html"
            }
        }
        //获取公告列表
        function loadNoticeList(url){
            $.ajax({
                type: "get",
                url:url,
                success:function (result){
                    if (result.code === "SUCCESS" && result.data != null){
                        let noticeList = result.data;
                        let finalHtml = '';
                        for (let notice of noticeList){
                            finalHtml += '<div class="notice-title">' + notice.title + '</div>';
                            finalHtml += '<div class="notice-content">' + notice.context + '</div>';
                            finalHtml += '<div style="display: flex; justify-content: space-between; align-items: center; margin-top: 15px;">';

                            // 发布人信息
                            finalHtml += '<div style="display: flex; align-items: center;">';
                            finalHtml += '<span style="color: #d23369; font-size: 14px; margin-right: 10px;">👤 ' + notice.userName + '</span>';
                            finalHtml += '<span style="color: #999; font-size: 12px;">⏱️ ' + notice.publishDateStatus + '</span>';
                            finalHtml += '</div>';

                            // 删除按钮(只有管理员可见)
                            if (power !== 0) {
                                finalHtml += '<button onclick="deleteNotice(\'' + notice.id + '\')" style="';
                                finalHtml += 'background-color: #ffebee;';
                                finalHtml += 'color: #ff4081;';
                                finalHtml += 'border: 1px solid #ffb8c6;';
                                finalHtml += 'padding: 3px 10px;';
                                finalHtml += 'border-radius: 15px;';
                                finalHtml += 'font-size: 12px;';
                                finalHtml += 'cursor: pointer;';
                                finalHtml += 'transition: all 0.3s;"';
                                finalHtml += 'onmouseover="this.style.backgroundColor=\'#ff4081\'; this.style.color=\'white\'"';
                                finalHtml += 'onmouseout="this.style.backgroundColor=\'#ffebee\'; this.style.color=\'#ff4081\'">';
                                finalHtml += '删除';
                                finalHtml += '</button>';
                            }
                            finalHtml += '</div>';
                            finalHtml += '</div>';
                        }
                        $("#notice").html(finalHtml);
                    }
                },
                error: function(error) {
                    if (error.status === 401) {
                        location.href = "login.html";
                    }
                }
            })
        }
        function deleteNotice(id) {
            if (power === 0){

                alert("您没有删除公告的权限")
            }else {
                if (confirm('确定要删除这条公告吗？')) {
                    $.ajax({
                        type: "post",
                        url: "notice/delete",
                        data:{
                            id:id
                        },
                        success: function(result) {
                            if (result.code === "SUCCESS") {
                                alert("删除成功");
                                loadNoticeList("notice/getNoticeList");
                            } else {
                                alert(result.errorMessage);
                            }
                        },
                        error: function(error) {
                            if (error.status === 401) {
                                location.href = "login.html";
                            }
                        }
                    });
                }
            }
        }
        $(document).ready(function() {
            loadNoticeList("notice/getNoticeList");
        });
    </script>
</body>
</html>